home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Talks & Papers / Michael D. Crawford↵ / Word Services SDK 1.0.5 / Writeswell Jr. Source / MyTextEdit.c < prev    next >
Text File  |  1993-03-08  |  1KB  |  65 lines

  1. /* MyTextEdit.c
  2.  * Useful utility routines for TextEdit in Writeswell Jr.
  3.  * Copyright ©1993 Working Software, Inc.  All Rights Reserved.
  4.  * 4 Mar 93 Mike Crawford
  5.  */
  6.  
  7. #include "Scroll.h"
  8. #include "MyTextEdit.h"
  9. #include "ArrowKeyCodes.h"
  10.  
  11. void MyTEKey( WindowPtr docWindow,
  12.                 ControlHandle vertScroll,
  13.                 char theChar,
  14.                 Boolean readOnly )
  15. {
  16.     TEHandle    textH;
  17.     short        numLines;
  18.     short        selStart;
  19.     Rect        viewRect;
  20.     Point        selPoint;
  21.     Boolean        inRect;
  22.  
  23.     textH = (TEHandle)GetWRefCon( docWindow );
  24.     
  25.     numLines = (*textH)->nLines;
  26.  
  27.     if ( readOnly ){
  28.  
  29.         /* We allow the cursor keys to be entered */
  30.  
  31.         switch ( theChar ){
  32.             case kLeftArrow:
  33.             case kRightArrow:
  34.             case kUpArrow:
  35.             case kDownArrow:
  36.                 break;
  37.             default:
  38.                 return;        
  39.         }    
  40.     }
  41.  
  42.     TEKey( theChar, textH );
  43.  
  44.     selStart = (*textH)->selStart;
  45.     
  46.     viewRect = (*textH)->viewRect;
  47.     
  48.     selPoint = TEGetPoint( selStart, textH );
  49.     
  50.     inRect = PtInRect( selPoint, &viewRect );
  51.  
  52.     if ( !inRect || numLines != (*textH)->nLines ){
  53.         /* We may need to reset the scroll bar if we changed the number of lines */
  54.         ShowSelection( textH );
  55.         SetVertScroll(    docWindow, vertScroll );
  56.     }
  57.  
  58.     return;
  59. }
  60.  
  61. TEHandle GetTextHandle( WindowPtr theWindow )
  62. {
  63.     return (TEHandle)GetWRefCon( theWindow );
  64. }
  65.